package cn.enjoy.service.impl;

import cn.enjoy.dao.UserMapper;
import cn.enjoy.model.User;
import cn.enjoy.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;

    @Override
    public boolean login(String username, String passwd) {
        User users = userMapper.findByUsernameAndPasswd(username, passwd);
        return users != null;
    }

    @Override
    public boolean register(String username, String passwd) {
        User users = new User();
        users.setUsername(username);
        users.setPasswd(passwd);
        int cnt = userMapper.insertSelective(users);
        return cnt > 0;
    }

    @Transactional
    @Override
    public void batchAdd(String username, String passwd) {
        User users = new User();
        users.setUsername(username);
        users.setPasswd(passwd);
        userMapper.insertSelective(users);
        int i = 10 /0;
        users = new User();
        users.setUsername(username+"2");
        users.setPasswd(passwd);
        userMapper.insertSelective(users);
    }
}
